package com.lmx.repoDomain.tmodel;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 资料共享
 *
 * @author ytche
 * @date 2017年7月21日
 *
 */
@JsonApiResource(type = "shareDocument")
@Entity
@Table(name = "tnb_share_document")
public class ShareDocument extends BaseEntity {

	private static final long serialVersionUID = 1L;
	private String name;
	private String remark;
	private DocumentType type;
	private Integer createTime;
	private Set<ShareDocumentFile> file;

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Lob
	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "type_id")
	public DocumentType getType() {
		return type;
	}

	public void setType(DocumentType type) {
		this.type = type;
	}

	@Column(name = "create_time")
	public Integer getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Integer createTime) {
		this.createTime = createTime;
	}

	@JsonApiToMany
	@JsonApiIncludeByDefault
	@OneToMany(fetch = FetchType.EAGER, mappedBy = "document", cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	public Set<ShareDocumentFile> getFile() {
		return file;
	}

	public void setFile(Set<ShareDocumentFile> file) {
		this.file = file;
	}

}
